perm filename QUEEN4.LSP[E82,JMC] blob sn#679493 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	queen4.lsp[e82,jmc]	New try at version that excludes squares already tried
C00004 ENDMK
CāŠ—;
queen4.lsp[e82,jmc]	New try at version that excludes squares already tried

(defun solutions (pos sols)
       (if (terp pos)
	   (if (winp pos) (cons (outform pos) sols) sols)
	   (do ((r (row pos) (cdr r))
		(p pos (sidedate tried p))
		(tried nil (car r))
		(s sols (solutions (update (car r) p) s)))
	       ((or (null r) (ter p)) s))))

;;; not correct: sidedating might win.  Taking this into accouht would
;;; be inefficient using  DO,  because the termination condition and
;;; the result computation need to share computation which isn't allowed.
;;; Multiple result functions that allowed the termination condition
;;; and the output to be the values of a single expression would win here.

;;; exclude contains all the consequences of excluding a square


(defun solutions (pos sols)
       (if (terp pos)
	   (if (winp pos) (cons (outform pos) sols) sols)
	   (sol1 (row pos) pos nil sols)))

(defun sol1 (r p tried s)
       (if (null r)
	   s
	   (if (terp p)
	       (if (winp p) (cons (outform p) s) s)
	       (sol1 (cdr r)
		     (sidedate tried p)
		     (car r)
		     (solutions (update (car r) p) s)))))

(defun sidedate (sq p)
       (if (null sq)
	   p
	   (exclude sq p)))